package org.emet.flex.util
{
	import mx.events.ValidationResultEvent;
	import mx.validators.Validator;
	import mx.containers.FormItem;
	
	public class ValidatorUtils
	{
		public function ValidatorUtils()
		{
		}

		public static function validateAll(validators:Array) : Boolean
		{
			var errors : Array =  Validator.validateAll(validators);
			if(errors.length > 0) {
				return false;
			}else {
				return true;
			}
		}
		
		public static function validateAndReturnMsg(validators:Array):String {
			var errors : Array =  Validator.validateAll(validators);
			var errMsg:String = "";
			if(errors.length > 0){
				var err:ValidationResultEvent;
				var errorMessageArray:Array = [];
				for each (err in errors) {
					var errField:String = FormItem(err.currentTarget.source.parent).label
					errorMessageArray.push(errField + ": " + err.message);
				}
				errMsg = errorMessageArray.join("\n\n");
			}
			return errMsg;
		}
	}
}